using NUnit.Framework;

namespace ValidationFramework.Tests
{
    [TestFixture]
	public class EnumConversionRuleAttributeTest
    {
        	const string enumTypeName = "ValidationFramework.Tests.EnumConversionRuleAttributeTest+Numbers, ValidationFramework.Tests";
            public enum Numbers
		{
			One = 1,
			Two = 2,
			Three = 3
		}
        [Test]
        public void CheckValuesUsingString()
		{
        	var ruleAttribute = new EnumConversionRuleAttribute(enumTypeName);
			Assert.AreEqual(typeof(Numbers), ruleAttribute.EnumType);

			var propertyRule = (EnumConversionRule)ruleAttribute.CreateInstance(new MockPropertyDescriptor<string>("foo"));
			var parameterRule = (EnumConversionRule)ruleAttribute.CreateInstance(new MockParameterDescriptor<string>("foo"));
			var fieldRule = (EnumConversionRule)ruleAttribute.CreateInstance(new MockFieldDescriptor<string>("foo"));

			Assert.AreEqual(typeof(Numbers), propertyRule.EnumType);
			Assert.AreEqual(typeof(Numbers), parameterRule.EnumType);
			Assert.AreEqual(typeof(Numbers), fieldRule.EnumType);


        }

        [Test]
        public void CheckValuesUsingType()
		{
            var ruleAttribute = new EnumConversionRuleAttribute(typeof(Numbers));
			Assert.AreEqual(typeof(Numbers), ruleAttribute.EnumType);

			var propertyRule = (EnumConversionRule)ruleAttribute.CreateInstance(new MockPropertyDescriptor<string>("foo"));
			var parameterRule = (EnumConversionRule)ruleAttribute.CreateInstance(new MockParameterDescriptor<string>("foo"));
			var fieldRule = (EnumConversionRule)ruleAttribute.CreateInstance(new MockFieldDescriptor<string>("foo"));

			Assert.AreEqual(typeof(Numbers), propertyRule.EnumType);
			Assert.AreEqual(typeof(Numbers), parameterRule.EnumType);
			Assert.AreEqual(typeof(Numbers), fieldRule.EnumType);


        }


        [Test]
        public void CallAttributeTester()
        {
			AttributeTester.CheckDefaultValues<string>(new EnumConversionRuleAttribute(enumTypeName), true, true, true);
			AttributeTester.CheckNonDefaultValues<string>(new EnumConversionRuleAttribute(enumTypeName), true, true, true);
            AttributeTester.CheckDefaultValues<string>(new EnumConversionRuleAttribute(typeof(Numbers)), true, true, true);
            AttributeTester.CheckNonDefaultValues<string>(new EnumConversionRuleAttribute(typeof(Numbers)), true, true, true);
        }

    }
}